import 'package:aweb5/bean/aplus/phone_code_entity.dart' as prefix0;
import 'package:aweb5/generated/json/phone_code_entity_helper.dart';
import 'package:flutter/material.dart';
import 'package:aweb5/widgetlib/LoginFormCode.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:aweb5/util/StringUtil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:aweb5/util/HttpClient.dart';
import 'package:aweb5/config/Config.dart';
import 'package:aweb5/bean/aplus/phone_code_entity.dart';
class RegisterWithPhone extends StatefulWidget {
  @override
  _RegisterWithPhoneState createState() => _RegisterWithPhoneState();
}

class _RegisterWithPhoneState extends State<RegisterWithPhone> {
  TextEditingController accountController = TextEditingController();
  TextEditingController passwordController = TextEditingController();
  bool check = false;


  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    requestCode();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: buildBody(context),
    );
  }

  Widget buildBody(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          SizedBox(height: 100,),
          Container(
            alignment: Alignment.centerLeft,
            height: 35,
            margin: EdgeInsets.only(left: 50, right: 50),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(5),
                color: Color(0xfff2f2f2)),
            child:
            Row(
              children: <Widget>[
                Expanded(
                  child: TextField(

                    controller: accountController,
                    keyboardType: TextInputType.number,
                    decoration: InputDecoration(
                      hintText: "请输入手机号",
                      hintStyle: TextStyle(
                        color: Color(0xffa1a1a1),
                        fontSize: 12,
                      ),
                      border: InputBorder.none,
                      contentPadding: EdgeInsets.only(left: 10.0),
//                  prefixIcon: Container(
//                    width: 1,
//                    height: 1,
//                    padding: const EdgeInsets.fromLTRB(15.0, 0, 15.0, 0),
//                    child: Center(
//                        child: Image.asset("assets/shd/zhanghao@3x.png")),
//                  )


                    ),
                  ),

                )
                ,

                InkWell(
                  child: Container(
                    width: 30,
                    height: 30,
                    padding: EdgeInsets.all(5),
                    child: Image.asset("assets/assist/guanbi1.png"),

                  ),
                  onTap: (){

                    Fluttertoast.showToast(msg: "close");

                  },
                )

              ],

            )
            ,
          ),
          SizedBox(
            height: 20,
          ),
          Container(
              alignment: Alignment.centerLeft,
              height: 35,
              margin: EdgeInsets.only(left: 50, right: 50),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5),
                  color: Color(0xfff2f2f2)),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Expanded(
                      child: TextField(
                        controller: passwordController,
                        obscureText: true,
                        keyboardType: TextInputType.text,
                        decoration: InputDecoration(
                            hintText: "请输入密码",
                            hintStyle: TextStyle(
                              color: Color(0xffa1a1a1),
                              fontSize: 12,
                            ),
                            border: InputBorder.none,
                            contentPadding: EdgeInsets.only(left: 10)

                        ),
                      )),

                  InkWell(
                    child: Container(
                      width: 30,
                      height: 30,
                      padding: EdgeInsets.all(5),
                      child: Image.asset("assets/assist/guanbi1.png"),

                    ),
                    onTap: (){

                      Fluttertoast.showToast(msg: "close");

                    },
                  ),

                  Container(
                    alignment: Alignment.center,
                    width: 100,
                    height: 35,
                    child: LoginFormCode(textEditingController: accountController,),
                  )
                ],
              )),

          InkWell(
            child: Container(
              margin: EdgeInsets.only(left: 50, right: 50, top: 30),
              height: 35,
              decoration: BoxDecoration(
                  color: Color(0xfff64269),
                  borderRadius: BorderRadius.circular(5)),
              child: Center(
                child: Text(
                  "注册",
                  style: TextStyle(fontSize: 18, color: Colors.white),
                ),
              ),
            ),
            onTap: () {
              if (!StringUtil.isPhone(accountController.text)) {
                Fluttertoast.showToast(msg: "请输入正确的手机号");
                return;
              }
//              request();
            },
          ),
          SizedBox(height: 10,),
          Row(
            children: <Widget>[
              SizedBox(width: 50,),
              Checkbox(value: check, onChanged: (v){

                this.check = !check;

              }),
              Text(" 我同意服务")
              
              
            ],
            
          ),
          
          
           
//          InkWell(
//            child: Container(
//              height: 60,
//              color: Color(0xffff9933),
//              child: Center(
//                child: Text(
//                  "登录即代表您已经同意《本协议》",
//                  style: TextStyle(color: Colors.grey),
//                ),
//              ),
//            ),
//            onTap: () {
//              Navigator.of(context).push(MaterialPageRoute(builder: (con) {
//                return Agreement();
//              }));
//            },
//          )
        ],
      ),
    );
  }


  void requestCode() async {
    try {
      Map<String, dynamic> map = Map<String, dynamic>();
      map["mobile"] = "18451130117";
//      map["password"] = passwordController.text;

      // map["client_id"]='9';

      Map<String, dynamic> map1 =
      await HttpClient.requestLogin(Config.requestApi + 'member/login/sendSms', data: map);

//      PhoneCodeEntity loginEntity = PhoneCodeEntity.fromJson(map1);
       PhoneCodeEntity phoneCodeEntity = new PhoneCodeEntity();
       PhoneCodeEntity l = phoneCodeEntityFromJson(phoneCodeEntity, map1);


//      l = l.fromJson(map1);
      Fluttertoast.showToast(msg: l.msg);
//      if (loginEntity == null) {
//        print("null");
//      } else if (loginEntity.success == 1) {
//        print(">>>>>>1");
//        HttpUtils.password = loginEntity.callInfo.password;
//        Config.name = loginEntity.callInfo.name;
//        Config.portrait = loginEntity.callInfo.portrait;
//        Config.dealers_id = loginEntity.callInfo.dealersId;
//
//        navigatorState.pushReplacement(new MaterialPageRoute(builder: (con) {
//          return ChangeShop();
//        }));
//      }
    } catch (e) {
      print(e.toString());
    }
  }


}
